package org.xiha.wiki;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

/**
 * Hello world!
 * 
 */
public class App {
	public static void main(String[] args) {

		Properties wikiP = new Properties();
		try {
			wikiP.load(ClassLoader.getSystemResourceAsStream("wiki.properties"));
		} catch (FileNotFoundException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}

		String wikiTemplates = wikiP.getProperty("wiki.templates");

		Properties p = new Properties();
		p.setProperty("file.resource.loader.path", wikiTemplates);
		p.setProperty("userdirective", "org.xiha.wiki.MyDirective");
		try {
			Velocity.init(p);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		VelocityContext context = new VelocityContext();

//		context.put("name", "summer");
		Template template = null;

		try {
			template = Velocity.getTemplate("mytemplate.vm");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		StringWriter sw = new StringWriter();
		try {
			template.merge(context, sw);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		System.out.println(sw);

	}
}
